package com.dream.keigezhushou.Activity.acty.personal.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.RelativeLayout;


import com.dream.keigezhushou.R;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 优惠券已使用
 */

public class AlreadyUseFragment extends Fragment {

    @BindView(R.id.discount_list)
    ListView discountList;
    private View mView;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {

        if (mView == null) {

            mView = LayoutInflater.from(getContext()).inflate(R.layout.layout_used_fragment, container, false);

        }

        ViewGroup viewGroup = (ViewGroup) mView.getParent();

        if (viewGroup != null) {

            viewGroup.removeView(mView);
        }
        ButterKnife.bind(this, mView);

        initData();
        return mView;
    }

    //初始化数据
    protected void initData(){

        //ListView设置间隔
        discountList.setDivider(null);
        discountList.setDividerHeight(30);
        //ListView创建适配器
        discountList.setAdapter(new UsedAdapter());
    }

    public class UsedAdapter extends BaseAdapter {

        int c = 6;

        public UsedAdapter() {
            super();
        }

        @Override
        public int getCount() {
            return c;
        }

        @Override
        public Object getItem(int i) {
            return i;
        }

        @Override
        public long getItemId(int i) {
            return i;
        }

        @Override
        public View getView(int i, View view, ViewGroup viewGroup) {

            ViewHolder mHolder = null;
            if (view == null){

                view = LayoutInflater.from(getContext()).inflate(R.layout.nouse_list_item,null);

                mHolder = new ViewHolder();

                mHolder.rlUse = (RelativeLayout) view.findViewById(R.id.use_quan);
                mHolder.ivUsed = (ImageView)view.findViewById(R.id.iv_used);
                mHolder.ivOverdue = (ImageView)view.findViewById(R.id.iv_overdue);

                view.setTag(mHolder);
            }else {

                mHolder = (ViewHolder)view.getTag();
            }

            mHolder.rlUse.setVisibility(View.GONE);
            mHolder.ivUsed.setVisibility(View.VISIBLE);
            mHolder.ivOverdue.setVisibility(View.GONE);
            return view;
        }


        class ViewHolder{

            RelativeLayout rlUse;
            ImageView ivUsed,ivOverdue;

        }
    }
}
